package com.example.shop.shops.controller;


import com.example.shop.ov.CodeDto;
import com.example.shop.shops.service.VerifyCodeService;
import com.example.shop.util.AjaxResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.EnableAsync;
import org.springframework.web.bind.annotation.*;

import java.io.IOException;

/**
 * 验证码
 */
@RestController
@CrossOrigin(origins = "*", maxAge = 3600)
@RequestMapping("/verifyCode")
public class VerifyCodeController {
    @Autowired
    private VerifyCodeService verifyCodeService;

    /**
     * 获取图形验证码
     */
    @GetMapping("/image/{imageCodeKey}")
    public AjaxResult graph(@PathVariable("imageCodeKey") String redisKey) throws IOException {
        String base64Graph = verifyCodeService.graph(redisKey);
        return AjaxResult.me().success(base64Graph);
    }


    @PostMapping("/smsCode")
    public AjaxResult smsCode(@RequestBody CodeDto codeDto) {
        verifyCodeService.getCode(codeDto);
        return AjaxResult.me().success();
    }
    @PostMapping("/melt")
    public AjaxResult Code(@RequestBody CodeDto codeDto) {
        verifyCodeService.getMelt(codeDto);
        return AjaxResult.me().success();
    }
}
